#include<iostream>
class Stack
{
public:
	Stack(int capacity = 4)
	{
		_a = (int*)malloc(sizeof(int) * capacity);
		if (_a == nullptr)
		{
			perror("malloc fail");
			exit(-1);
		}
		_top = 0;
		_capacity = capacity;
	}
	int* Checkcapacity()
	{
		if (_top != _capacity)
		{
			return nullptr;
		}
		int* tmp = (int*)malloc(sizeof(int) * _capacity * 2);
		if (tmp == nullptr)
		{
			perror("malloc fial");
			return nullptr;
		}
		_a = tmp;
		_capacity *= 2;
		return _a;
	}
	void Push(int x)
	{
		_a = Checkcapacity();
		_a[_top] = x;
		_top++;
	}
	~Stack()
	{
		free(_a);
		_a = nullptr;
		_top = _capacity = 0;
	}
private:
	int* _a;
	int _top;
	int _capacity;
};
int main()
{
	Stack st;
	st.Push(1);
	st.Push(1);
	st.Push(1);
	st.Push(1);
	st.Push(1);
	return 0;
}